package com.zh.business.config.quartz;

import com.zh.business.util.SchedulerJobUtil;
import lombok.extern.slf4j.Slf4j;
import org.quartz.SchedulerException;
import org.springframework.context.ApplicationListener;
import org.springframework.context.event.ContextRefreshedEvent;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * 描述: Quartz 监听器，项目启动从数据库加载需要进行执行的任务
 *
 * @author: yanglin
 * @Date: 2021-07-27-9:04
 * @Version: 1.0
 */
@Slf4j
@Component
public class QuartzInitLisenter implements ApplicationListener<ContextRefreshedEvent> {

    @Resource
    private SchedulerJobUtil schedulerAllJob;

    @Override
    public void onApplicationEvent(ContextRefreshedEvent event) {
        try {
            schedulerAllJob.scheduleJobs();
        } catch (SchedulerException e) {
            e.printStackTrace();
        }
    }
}
